#-*- coding: utf-8 -*-
from django.shortcuts import render_to_response
from django.contrib.auth import authenticate, login,  logout
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse

def Inicial(request):
    return render_to_response('inicial.html',  locals())
    

def Login(request):
    if request.method == 'POST':
        usuario = request.POST['txtUsuario']
        senha = request.POST['txtSenha']
        user = authenticate(username=usuario, password=senha)
        if user is not None:
            if user.is_active:
                login(request, user)
                
                if 'next' in request.GET:
                    strUrl = request.GET['next']
                else:
                    strUrl = '/principal/'
                
                return HttpResponseRedirect(strUrl)
            else:
                mensagem = 'Seu login ainda não esta ativo, por favor ative sua conta atraves do e-mail.'
                situacao = 's'
        else:
            mensagem = 'Usuário ou senha incorretos, verifique.'
            situacao = 's'
        return render_to_response('login.html', locals())
    else:
        
        return render_to_response('login.html', locals())


def Logoff(request):
    logout(request)
    return HttpResponseRedirect('/inicial/')
    
def ProjetoDescricao(request):
    return render_to_response('projeto/descricao.html',  locals())
    
def Colabore(request):
    return render_to_response('projeto/colabore.html',  locals())

def Principal(request):
    return render_to_response('principal.html', locals())

def Cadastros(request):
    return render_to_response('cadastros.html',  locals())
    
def Error_Access(request):
    return render_to_response('error_access.html',  locals())
